home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / vision / magiceye / ddd / ddd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-07  |  19.8 KB  |  923 lines

  1. /*-----------------------------------
  2. | Wir erstellen 3-D-Bilder
  3. | Eingabe-File:
  4. | a...  Figur ist hinter Bildebene
  5. | 1...  Figur ist vor Bildebene
  6. | SPACE Bildebene
  7. | zB:
  8. |              11
  9. |           12222221
  10. |        12233333333221
  11. |       1223333443333221
  12. |       12233344443333221
  13. |       1223333443333221
  14. |        12233333333221
  15. |           12222221
  16. |              11
  17. | Gibt so was wie 'ne Kugel, klar?
  18. --------------------------------------*/
  19.  
  20. /*---------------------------------------------------------------------*/
  21. /*----------------------------
  22. | Wenn TEST
  23. | definiert ist, werden
  24. | einige Infos ausgegeben,
  25. | die ich zum Testen brauche
  26. ------------------------------*/
  27.  
  28. /*------------------------
  29. | Informationen ausgeben?
  30. -------------------------*/
  31. #if 01
  32. #define TEST
  33. #endif
  34.  
  35. /*-------
  36. | Welche?
  37. --------*/
  38. #if defined (TEST)
  39.  
  40. #if 0
  41. #define PROFIL
  42. #define SAME_NUMBERS
  43. #define VERBOSE
  44. #define PATTERNS
  45. #define OFFSETS
  46. #define NO_GRAFIK
  47. #endif
  48.  
  49. #if 1
  50. #define VERSION
  51. #define GRAFIK_INFO
  52. #define ERRORS
  53. #endif
  54.  
  55. #endif
  56.  
  57. #if !defined (NO_GRAFIK)
  58. #define GRAFIK
  59. #endif
  60.  
  61.  
  62. /*---------------------------------------------------------------------*/
  63. #include <ctype.h>
  64. #include <ext.h>
  65. #include <stdio.h>
  66. #include <stdlib.h>
  67. #include <string.h>
  68. #include <time.h>
  69.  
  70. #include "tools.h"                /*------------------------------------------
  71.                                 | Optionen aus Kommando-Zeile holen
  72.                                 | File-Routinen:
  73.                                 | load_file(): File laden, Länge ermitteln
  74.                                 | unload_file(): dasselbe entfernen
  75.                                 | get_pn(): Pfad und Namen aus String holen
  76.                                 --------------------------------------------*/
  77.  
  78.  
  79. /*--------------------------
  80. | Zulässige Optionen für DDD
  81. ----------------------------*/
  82. #define PLINE_FLG        "/p"
  83. #define PFILE_FLG        "/q"
  84. #define FREQUENZ_FLG    "/f"
  85.  
  86.  
  87.  
  88.  
  89. /*--------------------------------------------------------------------------*/
  90. #define STD_FRQ  16                    /* Das Muster wiederholt sich!            */
  91. #define EBENEN      8                    /* Muß immer kleiner als std_frq sein    */
  92. #define MIN_LINE 80                    /* Mindestgröße für das Bild            */
  93. #define MIN_ROW  25                    /* Mindestgröße für das Bild            */
  94.  
  95. /*-----------------------------------------
  96. | Ebenen vor und hinter der Bildebene
  97. | NB: ASCII-Zeichen eintragen ('1' statt 1)
  98. -------------------------------------------*/
  99. #define MAX_VORNE     ('1'+EBENEN)
  100. #define MAX_HINTEN    ('a'+EBENEN)
  101. #define ERROR        0
  102.  
  103. #define max(a, b) ((a) > (b) ? (a) : (b))
  104. #define min(a, b) ((a) < (b) ? (a) : (b))
  105.  
  106.  
  107.  
  108. /*--------------------------------------------------------------------------*/
  109. /*-------------------------------------
  110. | Hier werden die Optionen gespeichert:
  111. | 2. Parameter == NULL <-> Listenende
  112. ---------------------------------------*/
  113. opt_list liste[] = { { PLINE_FLG, get_string, NULL, FALSE},
  114.                      { PFILE_FLG, get_string, NULL, FALSE},
  115.                      { FREQUENZ_FLG, get_number, NULL, FALSE},
  116.                      { NULL, NULL, NULL, FALSE}
  117.                    };
  118.  
  119.  
  120. /*---------
  121. | Bildgröße
  122. -----------*/
  123. int cc;        /* Anzahl Zeichen im Bild    */
  124. int _cc;    /* dito, in Text            */
  125. int rc;        /* Anzahl Zeilen            */
  126. int _lo;    /* Offset zum Zentrieren    */
  127. int ro;        /* innerhalb der Graphik    */
  128.  
  129.  
  130. /*---------------
  131. | Muster-Speicher
  132. -----------------*/
  133. char    *My_Pattern;
  134. long    pattern_size;
  135. int        std_frq;
  136. int        max_frq;
  137.  
  138. /*------------------------------
  139. | Hier wird der Text gespeichert
  140. --------------------------------*/
  141. char *text;
  142. int file_flg;     /* File? */
  143.  
  144. /*------------------------------
  145. | Die Muster für den Hintergrund
  146. --------------------------------*/
  147. char *pattern;
  148. /*---------------------------------------
  149. | Der Text in Höheninformation übersetzt.
  150. ----------------------------------------*/
  151. char *picture;
  152. /*-----------------------
  153. | Speicher für 3D-Grafik
  154. -------------------------*/
  155. char *grafik;
  156.  
  157.  
  158.  
  159. /*--------------------------------------------------------------------------*/
  160. /*----------
  161. | Prototypen
  162. ------------*/
  163. void free_text( void );                            /* atexit-Funktionen                 */
  164. void new_line( void );
  165.  
  166. int  set_options( opt_list *l);                    /* Optionen auswerten                */
  167.  
  168. int get_picture_size( char *f);                    /* Größe und Inhalt abfragen        */
  169.  
  170. void print_picture( void );                        /* Höheninformationen ausgeben        */
  171. void print_grafik( void );                        /* 3d-Grafik ausgeben                */
  172. void print_pattern( char *pattern);                /* Zum Testen: Pattern ausgeben        */
  173.  
  174. void fill_picture( char *picture, char *text);    /* Umwandlungsroutinen                */
  175.  int  get_offset( char c);
  176. void transform_picture( char *grafik, char *picture);
  177.  
  178. void make_patterns( char *pattern, int rc );    /* Muster erstellen und anpassen    */
  179. void remake_pattern( char *pattern, int frequenz, int i, int c);
  180. int  make_pixel( char *pattern );
  181.  
  182.  
  183. /*--------------------------------------------------------------------------*/
  184. /*-------------
  185. | Start of Code
  186. ---------------*/
  187. main( int argc, char *argv[])
  188. {
  189.     char p[140], n[14];
  190.     time_t tm;
  191.     int opt_c;
  192.  
  193.  
  194.     new_line();
  195.     atexit( new_line);
  196.  
  197. #if defined (SAME_NUMBERS)
  198.     srand( 1 );
  199. #endif
  200.  
  201. #if defined (VERSION)
  202.     printf("\nDD.TTP  (vers. %s)", __DATE__ );
  203. #endif
  204.  
  205.     /*-----------------
  206.     | Optionen einlesen
  207.     | und auswerten
  208.     -------------------*/
  209.     opt_c = get_options( argc, argv);
  210.     if( set_options( liste ) == FALSE )
  211.     {    exit( 0 );
  212.     }
  213.  
  214.  
  215.     /*---------------
  216.     | Falsche Angaben
  217.     -----------------*/
  218.     if( opt_c == argc )
  219.     {    printf("\n3-D grafix creator."
  220.                "\nusage: ddd [/pPATTERNLINE] [/qPATTERNFILE] [/fFREQUENZ] input_file"
  221.                "\nsee ddd.txt for more information.");
  222.                exit( 0 );
  223.     }
  224.  
  225.     /*-------------------
  226.     | Eingabe_file laden:
  227.     ---------------------*/
  228.     get_pn( p, n, argv[opt_c] );
  229.  
  230.     text = (char *)load_file( p, n, "r" );
  231.     if( text == NULL )
  232.     {    printf( "\nnot found: %s%s", p, n);
  233.         return -1;
  234.     }
  235.  
  236.     /*------------------
  237.     | Text_Informationen
  238.     --------------------*/
  239.     time( &tm );
  240.     printf("\n%s, compiled on %s", n, ctime( &tm) );
  241.  
  242.     /*--------------------
  243.     | Jetzt geht's looooos
  244.     ----------------------*/
  245.     if( get_picture_size( text ) == 0)
  246.     {
  247.         grafik = ( char *)malloc( cc * rc );
  248.         picture = ( char *)malloc( cc * rc );
  249.         pattern = ( char *)malloc( max_frq * rc );
  250.  
  251.         /*------------------------------------
  252.         | Text in Höheninformationen umwandeln
  253.         | *picture mit Daten von *text füllen
  254.         --------------------------------------*/
  255.         fill_picture( picture, text);
  256.  
  257. #if defined (PROFIL)
  258.         /*-------------------
  259.         | *picture darstellen
  260.         ---------------------*/
  261.         printf("\n\nHöhenprofil\n");
  262.         print_picture( );
  263. #endif
  264.  
  265.         /*--------------------------
  266.         | Die Zufallsmuster erzeugen
  267.         ----------------------------*/
  268.         make_patterns( pattern, rc );
  269.  
  270.         /*------------------------------
  271.         | picture in 3-D Bild übertragen
  272.         | Ändert patterns.
  273.         --------------------------------*/
  274.         transform_picture( grafik, picture );
  275.  
  276.  
  277.         /*-----------------
  278.         | 3-D Bild ausgeben
  279.         -------------------*/
  280. #if defined (GRAFIK)
  281.         print_grafik( );
  282. #endif
  283.  
  284.         free( pattern );
  285.         free( picture );
  286.         free( grafik );
  287.     }
  288.     unload_file( text );
  289.  
  290.     return 0;
  291. }
  292.  
  293.  
  294. /*--------------------------
  295. | atexit()
  296. ----------------------------*/
  297. void free_text( void )
  298. {
  299.     unload_file( My_Pattern );
  300. }
  301.  
  302.  
  303. void new_line( void )
  304. {    printf("\n");
  305. }
  306.  
  307.  
  308. /*----------------------------------------------------
  309. | Optionen auswerten:
  310. ------------------------------------------------------*/
  311. int set_options( opt_list *l)
  312. {
  313.     char p[200], n[14];
  314.     long c;
  315.  
  316.     /*-----------------
  317.     | Globale Variablen
  318.     -------------------*/
  319.     pattern_size = std_frq = STD_FRQ;
  320.     My_Pattern = NULL;
  321.     file_flg = FALSE;
  322.  
  323.     if( l[0].valid && l[1].valid )
  324.     {    printf("\nOptionen %s und %s schließen sich aus!", PLINE_FLG, PFILE_FLG);
  325.         return FALSE;
  326.     }
  327.  
  328.     /*-------------
  329.     | Eingabe_Zeile
  330.     ---------------*/
  331.     if( l[0].valid )
  332.     {
  333.         pattern_size = std_frq = (int)strlen( l[0].value );
  334.         My_Pattern = (char *)malloc( std_frq + EBENEN);
  335.         strcpy( My_Pattern, l[0].value );
  336.     }
  337.  
  338.  
  339.     /*------------
  340.     | Eingabe-File
  341.     --------------*/
  342.     if( l[1].valid )
  343.     {
  344.         get_pn( p, n, l[1].value );
  345.         My_Pattern = (char *)load_file( p, n, "r" );
  346.         if( My_Pattern == NULL )
  347.         {    printf("\ncan't load %s%s", p, n);
  348.         }else
  349.         {    /*---------------------------------
  350.             | Nur Zeichen >= SPACE sind erlaubt
  351.             | SPACE -> '_'
  352.             | Der Rest wird übersprungen
  353.             -----------------------------------*/
  354.             for( c = 0; c < act_fil_sz; c++)
  355.             {    if( My_Pattern[c] < ' ' )
  356.                 {    memcpy( &My_Pattern[c], &My_Pattern[c+1], act_fil_sz-c);
  357.                     c--;
  358.                     act_fil_sz--;
  359.                 }
  360.                 if( My_Pattern[c] == ' ' )
  361.                 {    My_Pattern[c] = '_';
  362.                 }
  363.             }
  364.             pattern_size = act_fil_sz;
  365.  
  366.             /*------------
  367.             | Was bin ich?
  368.             --------------*/
  369.             file_flg = TRUE;
  370.  
  371.             atexit( free_text );
  372.         }
  373.     }
  374.  
  375.  
  376.     /*---------
  377.     | Frequenz:
  378.     -----------*/
  379.     if( l[2].valid )
  380.     {    std_frq = (int)l[2].value;
  381.         if( l[0].valid)
  382.         {     std_frq = min( std_frq, (int )strlen( l[0].value ) );
  383.         }
  384.     }
  385.  
  386.     max_frq = std_frq + EBENEN;
  387.  
  388.     return TRUE;
  389. }
  390.  
  391. /*-------------------------------------------------------------------
  392. | Bild analysieren
  393. ---------------------------------------------------------------------*/
  394.  
  395. /*-------------------------------
  396. | Wie lang ist die längste Zeile?
  397. | Wie viele Zeilen hat das Bild?
  398. | Zeichen checken.
  399. ---------------------------------*/
  400. int get_picture_size( char *f)
  401. {
  402.     long c;
  403.     int al;
  404.     int ret;
  405.     char t;
  406.  
  407.     ret = 0;
  408.  
  409.     al = cc = 0;
  410.  
  411.     for( c = 0; c < act_fil_sz; c++ )
  412.     {
  413.         t = *(f+c);
  414.         if( (t >= '1' && t <= MAX_VORNE) ||
  415.             (t >= 'a' && t <= MAX_HINTEN) ||
  416.             t == '\n' || t == ' ')
  417.         {    ;
  418.         }else
  419.         {    printf("\nFile enthält falsches Zeichen >>%c<<in Zeile %d, Spalte %d", t, rc, al);
  420.             ret |= ~0;
  421.         }
  422.         if( *(f + c) == '\n' )
  423.         {    cc = max( al, cc );
  424.             al = 0;
  425.             rc++;
  426.         }
  427.         al++;
  428.     }
  429.  
  430.  
  431.     ro = _lo = 0;
  432.  
  433.     /*----------------------------------
  434.     | So groß ist das Bild wirklich:
  435.     | (wird von fill_picture() benötigt)
  436.     ------------------------------------*/
  437.     _cc = cc;
  438.  
  439.     /*-----------------------------------
  440.     | Noch einen Rahmen um's Bild machen.
  441.     | Weil's leichter zu sehen ist.
  442.     -------------------------------------*/
  443.     cc += std_frq * 2;
  444.  
  445.     /*----------------
  446.     | Bild zentrieren:
  447.     ------------------*/
  448.     if( cc < MIN_LINE )
  449.     {    cc = MIN_LINE;
  450.     }
  451.     _lo = ( cc - _cc ) / 2;
  452.  
  453.  
  454.     if( rc < MIN_ROW )
  455.     {    ro = (MIN_ROW - rc) / 2;
  456.         rc = MIN_ROW;
  457.     }
  458.  
  459. #if defined (VERBOSE)
  460.     printf("\n%d * %d / offset: %d, %d", cc, rc, _lo, ro );
  461.     printf("\n%ld Bytes in file", act_fil_sz);
  462. #endif
  463.  
  464.     return ret;
  465. }
  466.  
  467.  
  468.  
  469. /*-------------------------------------------------------------------
  470. |                          Bildschirmausgabe
  471. ---------------------------------------------------------------------*/
  472.  
  473. /*-----------------------------------------
  474. | Auf den Schirm!
  475. | 3d-codiertes Bild
  476. -------------------------------------------*/
  477. void print_grafik( void )
  478. {
  479.     int x, y;
  480.     long o;
  481.  
  482. #if defined (VERBOSE)
  483.     printf("\n\n3d-Grafik: Frequenz = %d \n", std_frq);
  484. #endif
  485.  
  486.     /*----------------------
  487.     | Markierungen schreiben
  488.     ------------------------*/
  489.     printf("\n");
  490.     for( x = 0; x < (MIN_LINE - std_frq) / 2; x++)
  491.         printf(" ");
  492.     printf("x");
  493.     for( x = 1; x < std_frq; x++)
  494.         printf(" ");
  495.     printf("x");
  496.  
  497.     for( y = 0; y < rc; y++ )
  498.     {
  499.         printf("\n");
  500.  
  501.         for( x = 0; x < cc; x++ )
  502.         {    o = x + y * cc;
  503.             /*----------------
  504.             | Nächste Stelle
  505.             ------------------*/
  506.             printf("%c", grafik[o] );
  507.         }
  508.  
  509.     }
  510.     printf("\n\n");
  511. #if defined (TEST)
  512.     getch();
  513. #endif
  514. }
  515.  
  516.  
  517. /*-----------------------------------------
  518. | Auf den Schirm!
  519. | Zahlwerte + EBENEN werden ausgegeben.
  520. | -> Werte liegen zwischen 0 und 2 * EBENEN
  521. | EBENEN     = Leere Fläche
  522. | 0          = Nächste Ebene
  523. | 2 * EBENEN = entfernteste Ebene
  524. -------------------------------------------*/
  525. void print_picture( void )
  526. {
  527.     int x, y;
  528.     long o;
  529.  
  530.     for( y = 0; y < rc; y++ )
  531.     {
  532.         printf("\n     ");
  533.  
  534.         for( x = 0; x < cc; x++ )
  535.         {    o = x + y * cc;
  536.             /*----------------
  537.             | Nächste Stelle
  538.             ------------------*/
  539.             printf("%d", picture[o] + EBENEN);
  540.         }
  541.  
  542.     }
  543.     getch();
  544. }
  545.  
  546.  
  547.  
  548.  
  549. /*----------------
  550. | Testfunktion:
  551. | Pattern ausgeben
  552. ------------------*/
  553. void print_pattern( char *p)
  554. {
  555.     int i;
  556.  
  557.     for( i = 0; i < max_frq; i++)
  558.     {    printf("%c", *( p + i ) );
  559.     }
  560. }
  561.  
  562.  
  563.  
  564. /*---------------------------------------------------------------------
  565. |                              Hilfsfunktionen
  566. -----------------------------------------------------------------------*/
  567.  
  568.  
  569.  
  570. /*-----------------------
  571. | Zufallsmuster erstellen
  572. -------------------------*/
  573. void make_patterns( char *pattern, int rc )
  574. {
  575.     int c, d;
  576.     int y;
  577.     int po;
  578.     char h;
  579.  
  580.     c = 0;
  581.  
  582.     for( y = 0; y < rc; y++ )
  583.     {
  584.         po = y * max_frq;
  585.  
  586.         /*--------------------------------
  587.         | String mit Zufallszeichen füllen
  588.         ----------------------------------*/
  589.         for( d = 0; d < std_frq ; d++ )
  590.         {
  591.             /*--------------
  592.             | Muster füllen:
  593.             ----------------*/
  594.             if( My_Pattern )
  595.             {    /*------------------------
  596.                 | Brief:
  597.                 | Letztes Zeichen ist '|'
  598.                 | wg Lesbarkeit
  599.                 -------------------------*/
  600.                 if( file_flg && (d == std_frq - 1 ) )
  601.                 {    h = '|';
  602.                 }else
  603.                 {    h = My_Pattern[ c++ % pattern_size];
  604.                 }
  605.             }else
  606.             {    /*-----------
  607.                 | Zufallszahl
  608.                 -------------*/
  609.                 h = make_pixel( pattern + po);
  610.             }
  611.             pattern[ po + d ] = h;
  612.         }
  613.     }
  614. }
  615.  
  616.  
  617. /*----------------------------
  618. | einen Zufalls-Wert erzeugen,
  619. | wie ihn die grafik braucht.
  620. | Keine Wiederholung zulassen
  621. ------------------------------*/
  622. int make_pixel( char *pattern )
  623. {
  624.     int i;
  625.     int c;
  626.     int go;
  627.  
  628.     do
  629.     {
  630.         c = rand( ) / 600 + ' ' + 1 ;
  631.  
  632.         go = 0;
  633.         for( i = 0; i < max_frq; i++ )
  634.         {
  635.             if( c == pattern[i] )
  636.             {    go = ~0;
  637.                 break;
  638.             }
  639.         }
  640.     }while( go );
  641.  
  642.     return c;
  643. }
  644.  
  645.  
  646. /*--------------------------------------
  647. | Zufallsmuster ändern:
  648. |---------------------------------------
  649. | Im Pattern pattern
  650. | der Länge  f (alte Länge)
  651. | ab index   i
  652. |            c Zeichen einfügen (c > 0 )
  653. |             (neue Werte erzeugen)
  654. |             c Zeichen löschen  (c < 0 )
  655. ----------------------------------------*/
  656. void remake_pattern( char *pattern, int f, int i, int c)
  657. {
  658.     int d;
  659.  
  660. #if defined (PATTERNS)
  661.     print_pattern( pattern );
  662.     printf("    adr: %8lx   /   f: %2d   /   i: %2d   /   c: %2d\n", pattern, f, i, c);
  663. #endif
  664.  
  665.     /*-------
  666.     | Löschen
  667.     ---------*/
  668.     if( c < 0 )
  669.     {
  670.         /*------------------
  671.         | Muster verschieben
  672.         --------------------*/
  673.         memcpy( pattern + i , pattern + i + abs(c) , f - i - abs(c) );
  674.  
  675.     }else
  676.     /*--------
  677.     | Einfügen
  678.     ----------*/
  679.     {
  680.         /*------------------
  681.         | Muster verschieben
  682.         --------------------*/
  683.         memcpy( pattern + i + c, pattern + i, f - i );
  684.  
  685.         /*---------------------
  686.         | Zeichen überschreiben
  687.         -----------------------*/
  688.         for( d = i; d < i + c; d++ )
  689.         {    *(pattern + d ) = make_pixel( pattern );
  690.         }
  691.     }
  692.  
  693. #if defined (PATTERNS)
  694.     print_pattern( pattern );
  695. #endif
  696.  
  697. }
  698.  
  699. /*-------------------------------------------
  700. | Wie weit muß das Zeichen verschoben werden?
  701. | Eingabe: Zeichen für Höhe (ASCII-File)
  702. | Ausgabe: Offset für 3D-File
  703. ---------------------------------------------*/
  704. int get_offset( char c)
  705. {
  706.     int offset;
  707.  
  708.     if( c == ' ' )
  709.     {    offset = 0;
  710.     }else if( c >= '1' && c <= MAX_VORNE)
  711.     {    offset = '1' - c - 1;
  712.     }else if( c >= 'a' && c <= MAX_HINTEN)
  713.     {    offset = c - 'a' + 1;
  714.     }else
  715.     {
  716. #if defined (ERRORS)
  717.         printf("\nFalscher Wert: %d", c);
  718. #endif
  719.         offset = ERROR;
  720.     }
  721.  
  722.     return offset;
  723. }
  724.  
  725.  
  726. /*-------------------------------------------------------------------
  727. |                       Umwandlungsroutinen
  728. ---------------------------------------------------------------------*/
  729.  
  730. /*-----------------------------------
  731. | Das Bild wird mit den Informationen
  732. | über die Höhe gefüllt.
  733. | Bild ist zentriert!
  734. |------------------------------------
  735. | Es gilt:
  736. | Wert < 0: Bild liegt vor Ebene
  737. | Wert = 0: Bild liegt in Ebene
  738. | Wert > 0: Bild liegt hinter Ebene
  739. -------------------------------------*/
  740. void fill_picture( char *picture, char *text)
  741. {
  742.     int x, y;
  743.     int to;
  744.  
  745.  
  746.     to = 0;
  747.  
  748.     for( y = 0; y < rc; y++)
  749.     {
  750.         for( x = 0; x < cc; x++)
  751.         {
  752.             /*---------------
  753.             | Rahmen erzeugen
  754.             -----------------*/
  755.             if( y < ro || y > rc - ro || x < _lo || x > cc - _lo )
  756.             {    *picture++ = 0;
  757.             }else
  758.             {
  759.                 /*---------------------------
  760.                 | Bildinformationen speichern
  761.                 -----------------------------*/
  762.                 if( to < act_fil_sz && text[to] != '\n' )
  763.                 {    *picture++ = get_offset( text[to] );
  764.                     to++;
  765.                 }else
  766.                 {    *picture++ = 0;
  767.                 }
  768.             }
  769.         }
  770.         if( y >= ro && to < act_fil_sz )
  771.         {    to++;
  772.         }
  773.     }
  774. }
  775.  
  776.  
  777. /*-------------------------------------------------------------
  778. | In das Feld wird eingetragen, welcher Offset im Muster in die
  779. | 3d-Grafik gehört.
  780. ---------------------------------------------------------------
  781. | selbe Höhe -> gleicher Offset
  782. | x näher    -> Offset - x
  783. | x weiter   -> Offset + x
  784. ---------------------------------------------------------------*/
  785. void transform_picture( char *grafik, char *picture)
  786. {
  787.     int x, y;            /* Wo sind wir?                                */
  788.     int offset;            /* Abstand Hintergrund / Bildpunkt            */
  789.     int alter_offset;    /* vorheriger Wert                            */
  790.     int d_o;            /* Änderung im Offset                        */
  791.     int frequenz;        /* Wiederholung des Musters                    */
  792.     int t;                /* Helferlein                                */
  793.     int i;                /* Index für Zufallsmuster                    */
  794.     int pp;                /* Pointer auf aktuelles Pattern             */
  795.  
  796.  
  797. #if defined (OFFSETS)
  798.     printf("\033E\n\nOffset-Erstellung");
  799. #endif
  800.  
  801.     for( y = 0; y < rc; y++)
  802.     {
  803.         /*-------------------
  804.         | Da steht das Muster
  805.         ---------------------*/
  806.         pp = y * ( max_frq );
  807.  
  808. #if defined (OFFSETS)
  809.         printf("\n");
  810. #endif
  811.  
  812.         /*------------------
  813.         | Anfang des Musters
  814.         --------------------*/
  815.         i = 0;
  816.         frequenz = std_frq;
  817.         alter_offset = 0;
  818.  
  819.         /*---------------------
  820.         | Von rechts nach links
  821.         -----------------------*/
  822.         for( x = 0; x < cc; x++)
  823.         {
  824.             /*------------
  825.             | Da sind wir:
  826.             --------------*/
  827.             t = y * cc + x;
  828.  
  829.  
  830.             /*-----------------------------------------
  831.             | offset gibt an, um wieviel das Muster an der
  832.             | entsprechenden Stelle verschoben sein muß.
  833.             | offset ist ok!
  834.             -------------------------------------------*/
  835.             offset = picture[ t ];
  836.  
  837.             /*------------------------
  838.             | rel. Änderung im Muster:
  839.             -------------------------*/
  840.             d_o = offset - alter_offset;
  841.  
  842.  
  843. #if defined (OFFSETS)
  844.             /*-------------------------
  845.             | Normale Schrift
  846.             ---------------------------*/
  847.             printf("\033q");
  848. #endif
  849.             /*----------------------------
  850.             | Es gibt eine Änderung
  851.             | -> Altes (!) Muster anpassen
  852.             |    also auch: alte Parameter
  853.             -----------------------------*/
  854.             if( d_o )
  855.             {
  856. #if defined (OFFSETS)
  857.             /*---------------
  858.             | Inverse Schrift
  859.             -----------------*/
  860.             printf("\033p");
  861.  
  862. #endif
  863.                   remake_pattern( pattern + pp, frequenz, i, d_o);
  864.                 alter_offset = offset;
  865.             }
  866.  
  867.             /*----------------------------------------------------------
  868.             | Werte neu berechnen
  869.             -----------------------------------------------------------*/
  870.  
  871.             /*--------------
  872.             | Neue Frequenz:
  873.             ----------------*/
  874.             frequenz = std_frq + offset;
  875.  
  876.             /*-------------------------------
  877.             | index an neue Frequenz anpassen
  878.             --------------------------------*/
  879.             if( d_o )
  880.             {    i %= frequenz;
  881.             }
  882.  
  883.             /*-------------------------------
  884.             | Wert im Grafikspeicher ablegen
  885.             ---------------------------------*/
  886.             grafik[ t ] = pattern[ pp + i ];
  887.  
  888.             /*--------------
  889.             | Nächster Index
  890.             ----------------*/
  891.             i = (i + 1) % frequenz;
  892.  
  893. /*---------------------------------
  894. | Information auf Bildschirm zeigen
  895. -----------------------------------*/
  896. #if defined (OFFSETS)
  897. #if 0
  898.             /*-----------------------------
  899.             | Offsets:
  900.             | Nur die mittleren 40 Zeichen!
  901.             -------------------------------*/
  902.             if( abs( MIN_LINE / 2 - x ) < 20 )
  903.             {
  904.                 printf("%2d", i);
  905.             }
  906. #else
  907.             /*-------------
  908.             | Grafik: Alles
  909.             ---------------*/
  910.             printf("%c", grafik[t] );
  911.  
  912. #endif
  913. #endif
  914.         }
  915.     }
  916.  
  917. #if defined (OFFSETS)
  918.     getch();
  919. #endif
  920.  
  921. }
  922.  
  923.